//
//  ChainSearchHistoryCell.m
//  Chain
//
//  Created by zhaosh on 2018/4/4.
//  Copyright © 2018年 zhaosh. All rights reserved.
//

#import "ChainSearchHistoryCell.h"

@interface ChainSearchHistoryCell()
@property(strong,nonatomic)UILabel *titleL;
@property(strong,nonatomic)UIButton *deleteBtn;
@property(strong,nonatomic)UIView *line;

@end

@implementation ChainSearchHistoryCell

#pragma mark converse init method
+ (instancetype)cellWithTableView:(UITableView *)tableView
{
    static NSString *identifier = @"ChainSearchHistoryCell";
    ChainSearchHistoryCell *cell = (ChainSearchHistoryCell *)[tableView dequeueReusableCellWithIdentifier:identifier];
    if (cell == nil){
        cell = [[ChainSearchHistoryCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    return cell;
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.backgroundColor = [UIColor whiteColor];
        [self setContentView];
    }
    return self;
}

-(void)setContentView{
    self.titleL = [UILabel new];
    self.titleL.font = [UIFont systemFontOfSize:16];
    self.titleL.textColor = HEXCOLOR(@"#666666");
    [self.contentView addSubview:self.titleL];
    
    self.deleteBtn = [UIButton new];
    [self.deleteBtn setImage:[UIImage imageNamed:@"guanbi"] forState:UIControlStateNormal];
    self.deleteBtn.contentMode = UIViewContentModeCenter;
    [self.deleteBtn addTarget:self action:@selector(deleteClicked) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:self.deleteBtn];
    
    self.line = [UIView new];
    self.line.backgroundColor = HEXCOLOR(@"#f0f0f0");
}

-(void)layoutSubviews{
    [super layoutSubviews];
    
    self.titleL.frame = CGRectMake(20, (self.height - 17)/2., self.width - 100, 17);
    self.titleL.text = self.item.titlename;
    self.deleteBtn.frame = CGRectMake(self.width -60, 0, 60, self.height);
    self.deleteBtn.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, -22);
}

-(void)deleteClicked{
    if ([self.delegate respondsToSelector:@selector(searchdeleteActionWithCell:)]) {
        [self.delegate searchdeleteActionWithCell:self];
    }
}

@end
